<?php
namespace Kuoqi\Interpreter;

class Php{
	static protected $assign,$code;
	static public function execCode($code,$assign){
		self::$assign = $assign;
		self::$code = $code;
		self::__initializate();
		$code = self::$code;
		self::$code = '';
		return 	$code;		
	}
	static public function __initializate(){
		$data = self::$code;
		//替换前置标签
		$data=str_replace("<php>","<?php ",$data);
		//替换后置标签
		$data=str_replace("</php>","?>",$data);
		//获取标签内部 data-php = "" 获取标签内容
		preg_match_all(self::need(),$data,$arr);
		foreach($arr[0] as $k=>$v){
			$data = str_replace($v,self::replace($arr[1][$k]),$data);
		}
		self::$code = trim($data,"\t\n\r\0\x0B");
		return NULL;
	}
	
	static private function need(){
		return '/data\-php\=[\'\"]\{(.*)\}[\'\"]/';
	}
	
	static private function replace($val){
		return '<?php '.$val.'?>';
	}
}